<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
   
	//author-> http://bytes.com/forum/member.php?u=10289
	//site -> http://bytes.com/forum/thread771412.html

// ------------------------------------------------------------------------

/**
 * Random Element - Takes an array as input and returns a random element
 *
 * @access	public
 * @param	array
 * @return	mixed	depends on what the array contains
 * input  => directory path
 * output => directories name array under that path 
 */	
if ( ! function_exists('getDirectory'))
{      
	  function getDirectory( $path = '.', $level = 0 )
      {
        // Directories to ignore when listing output. 
        $ignore = array( '.', '..' );
        // Open the directory to the handle $dh
        $dh = @opendir($path) or die("Unable to open $path");;
        // Loop through the directory
        while( false !== ( $file = readdir( $dh ) ) ) 
        {
           // Check that this file is not to be ignored
           if( !in_array( $file, $ignore ) )
           {  
               // Indent spacing for better view
               $spaces = str_repeat( '&nbsp;', ( $level * 5 ) );
              // Show directories only
              if(is_dir( "$path/$file" ) )
              {
                 // Re-call this same function but on a new directory.   
                 // this is what makes function recursive.                           
                 $themes_dir[]= $file;
                
				 //I'm commenting this line to make it one level only
				 //getDirectory( "$path/$file", ($level+1) );
				 //***remove above comment to make it recursive list of directories.
				 
				 
              }
           }
        }
        // Close the directory handle   
        closedir( $dh );
		
		//return array with directory names
		return $themes_dir;
      }


	
}


/* End of file list_dir_helper.php */
/* Location: ./system/application/helpers/list_dir_helper.php */